package com.jsb.laundry.common.enums;

/**
 * 订单状态
 */
public enum OrderStatus {

    UNKNOWN_ORDER_STATUS("404","未知的订单状态"),
    ORDER_DIRECTION1("订单物流方向，1 取","1"),
    ORDER_DIRECTION2("订单物流方向，2 送","2"),
    WAIT_PAY("0","待支付"),
    SUCCESS_PAY("1","已支付"),
    CANCEL_PAY("2","已取消"),
    SYSTEM_CANCEL_ORDER_PAY("3","已关闭(30分钟未支付系统自动关闭)"),
    APPLY_REFUND("4","已申请退款"),
    REFUNDING("5","退款中"),
    SUCCESS_REFUND("6","已退款"),


    ORDER_RECEIVED("7","已接单"),
    SUCCESS_PICKUP("8","已取件"),
    SUCCESS_ARRIVED("10","已送达"),
    ORDER_SUCCESS("11","已完成"),
    SUCCESS_IN_STORAGE("a","已入库(清洗中)"),
    SUCCESS_OUT_STORAGE("b","已出库(清洗完成)"),
    BACK_PICKUP("c","已出库-取件"),


    BACK_ARRIVED("d","已出库-送达"),
    ORDER_OK("e","已完成-订单最终状态 (用户确认收货)"),
    HANDOVER("f","已交接"),
    HAVE_BEEN_SIGNED("g","已签收"),
    SIGN_FOR_SB("h","代签收"),
    PLACE("i","放指定位置"),
    FACTORY_ORDERS_STATUS1("f1","工厂未入库"),
    FACTORY_ORDERS_STATUS2("f2","工厂已入库"),
    FACTORY_ORDERS_STATUS3("f3","工厂已检查"),
    FACTORY_ORDERS_STATUS4("f4","工厂已出库"),

    ;

    private String code;

    private String msg;

    OrderStatus(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


    /**
     * 根据code找枚举名
     *
     * @param code
     * @return
     */
    public static String getNameById(String code) {
        for (OrderStatus value : values()) {
            if (value.getCode().equals(code)) {
                return value.name();
            }
        }
        return null;
    }

    /**
     * 根据枚举名查找是否存在该枚举对象
     *
     * @param enumName
     * @return (true 存在, false 不存在)
     */
    public static Boolean supportEnum(String enumName) {
        for (OrderStatus value : values()) {
            if (value.name().equals(enumName)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 根据枚举name找枚举对象
     *
     * @param name
     * @return
     */
    public static OrderStatus getEnumObjByName(String name) {
        return OrderStatus.valueOf(name);
    }

    /**
     * 找枚举对象
     * @param orderStatus
     * @return
     */
    public static OrderStatus getEnumObj(OrderStatus orderStatus) {
        for (OrderStatus value : values()) {
            if (value.getCode().equals(orderStatus.getCode())) {
                return value;
            }
        }
        return OrderStatus.UNKNOWN_ORDER_STATUS;
    }

}
